function e(e) {
    return e ? "string" != typeof e ? e : new Date(e.replace(/"T"/, " ").replace(/\+[0-9]+/, "")) : null;
}

function t(e) {
    var t = e, r = new Date(t);
    return r.setHours(r.getHours() - 8), r;
}

function r(e) {
    return (e = e.toString())[1] ? e : "0" + e;
}

var n = function() {
    function e(e, t) {
        var r = [], n = !0, a = !1, o = void 0;
        try {
            for (var i, u = e[Symbol.iterator](); !(n = (i = u.next()).done) && (r.push(i.value), 
            !t || r.length !== t); n = !0) ;
        } catch (e) {
            a = !0, o = e;
        } finally {
            try {
                !n && u.return && u.return();
            } finally {
                if (a) throw o;
            }
        }
        return r;
    }
    return function(t, r) {
        if (Array.isArray(t)) return t;
        if (Symbol.iterator in Object(t)) return e(t, r);
        throw new TypeError("Invalid attempt to destructure non-iterable instance");
    };
}(), a = require("../config/constants.js");

module.exports = {
    formatTime: function(e) {
        var t = e.getFullYear(), n = e.getMonth() + 1, a = e.getDate(), o = e.getHours(), i = e.getMinutes(), u = e.getSeconds();
        return [ t, n, a ].map(r).join("/") + " " + [ o, i, u ].map(r).join(":");
    },
    formatCurrentDate: function(t) {
        return (t = e(t)).getFullYear() + "年" + (t.getMonth() + 1) + "月" + t.getDate() + "日";
    },
    formatNumber: r,
    getSpecificHourByDate: function(n) {
        var a = t(e(n));
        return [ a.getHours(), a.getMinutes() ].map(r).join(":");
    },
    getSpecificDayByDate: function(r) {
        var n = t(r = e(r)).getHours();
        (n > 16 || 16 === n) && r.setDate(r.getDate() - 1);
        var a = this.getWeekByDate(r);
        return r.getMonth() + 1 + "月" + r.getDate() + "日 " + a;
    },
    getUserSpecificHourByDate: function(t) {
        var n = e(t);
        return [ n.getHours(), n.getMinutes() ].map(r).join(":");
    },
    getUserSpecificDayByDate: function(t) {
        var t = e(t), r = this.getWeekByDate(t);
        return t.getMonth() + 1 + "月" + t.getDate() + "日 " + r;
    },
    getWeekByDate: function(t) {
        var r = e(t).getDay();
        return new Array("周日", "周一", "周二", "周三", "周四", "周五", "周六")[r];
    },
    getWeekDayByDate: function(t) {
        var r = e(t).getDay();
        return new Array("星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六")[r];
    },
    getDate: e,
    getDateStr: function(e) {
        var t = new Date();
        return t.setDate(t.getDate() + e), t.getFullYear() + "-" + (t.getMonth() + 1) + "-" + t.getDate();
    },
    toDecimal: function(e) {
        var t = parseFloat(e);
        if (isNaN(t)) return !1;
        var r = (t = Math.round(100 * e) / 100).toString(), n = r.indexOf(".");
        for (n < 0 && (n = r.length, r += "."); r.length <= n + 2; ) r += "0";
        return r;
    },
    timeToTimestamp: function(e) {
        return new Date(1e3 * parseInt(e)).toLocaleString().substr(0, 6);
    },
    transformDiffDate: function(e, t, r) {
        var n = e - t, a = parseInt(n / 60 / 60 / 24), o = parseInt(n / 60 / 60) - 24 * a, i = parseInt(n / 60) - 60 * parseInt(n / 60 / 60), u = "年:个月:天:小时:分钟:秒".split(":");
        n -= 60 * parseInt(n / 60), 6 != u.length && (u = [ "year(s)", "month(s)", "day(s)", "hour(s)", "minute(s)", "second(s)" ]);
        var s = r || "{0}", g = [ 0, 0, a, o, i, n ];
        if (s.indexOf("{0} {1}") > -1 || s.indexOf("{0}{1}") > -1) for (l = 2; l < 6; l++) if (g[l] > 0 || 5 == l) return M = u[l], 
        M = g[l] > 1 ? M.replace("(s)", "s") : M.replace("(s)", ""), s.replace("{0}", g[l]).replace("{1}", M);
        for (var c = "", f = 0, l = 2; l < 6; l++) if (g[l] > 0 || 5 == l && 0 == f) {
            var M = u[l];
            if (M = g[l] > 1 ? M.replace("(s)", "s") : M.replace("(s)", ""), c += g[l] + " " + M + " ", 
            ++f > 2) break;
        }
        return s.replace("{0}", c.trim());
    },
    transformSessionDiffDate: function(n) {
        var a = t(n = e(n)), o = a.getHours(), i = a.getMinutes();
        return (o > 16 || 16 === o) && n.setDate(n.getDate() - 1), this.getWeekDayByDate(n) + " " + (n.getMonth() + 1) + "月" + n.getDate() + "日, " + n.getFullYear() + " " + [ o, i ].map(r).join(":");
    },
    timestampToTime: function(e) {
        var t = new Date(1e3 * e);
        return t.getFullYear() + "-" + (t.getMonth() + 1 < 10 ? "0" + (t.getMonth() + 1) : t.getMonth() + 1) + "-" + t.getDate() + " " + t.getHours() + ":" + t.getMinutes() + ":" + t.getSeconds();
    },
    orderBy: function(e, t, r) {
        if (e instanceof Array && t instanceof Array && t.length > 0) {
            var a = t.concat([]), o = r || "asc", i = [], u = {};
            return function e(t, r, a) {
                t.sort(function(e, t) {
                    var n = e[r[0]], a = t[r[0]];
                    return "string" == typeof n && "string" == typeof a ? "ASC" == o.toUpperCase() ? n.localeCompare(a) : a.localeCompare(n) : "ASC" == o.toUpperCase() ? n - a : a - n;
                });
                var u = new Map();
                t.forEach(function(e) {
                    u.has(e[r[0]]) ? u.get(e[r[0]]).push(e) : (u.set(e[r[0]], []), u.get(e[r[0]]).push(e));
                }), r.shift();
                var s = !0, g = !1, c = void 0;
                try {
                    for (var f, l = u[Symbol.iterator](); !(s = (f = l.next()).done); s = !0) {
                        var M = n(f.value, 2), D = M[0], p = M[1];
                        a[D] = {}, a[D].name = D, a[D].value = p.length, 0 == r.length ? i = i.concat(p) : (a[D].children = {}, 
                        e(p, r.concat([]), a[D].children));
                    }
                } catch (e) {
                    g = !0, c = e;
                } finally {
                    try {
                        !s && l.return && l.return();
                    } finally {
                        if (g) throw c;
                    }
                }
            }(e, a, u), {
                results: i,
                totalSum: u
            };
        }
        return e;
    },
    errImgFun: function(e, t) {
        var r = {};
        r[e.target.dataset.errImg] = a.ERR_IMG, t.setData(r);
    },
    countDown: function(t) {
        var n = new Date(), a = e(t), o = (a.getTime() - n.getTime()) / 6e4, i = (Math.round(o), 
        (a.getTime() - n.getTime()) / 36e5), u = Math.round(i), s = s = (s = i - u) < 0 ? 60 - 60 * (u - i) : 60 * (i - u), s = Math.round(s - .495), g = (a.getTime() - n.getTime()) / 864e5, c = Math.round(g), f = f = (f = g - c) < 0 ? 24 - 24 * (c - g) : 24 * (g - c), f = Math.round(f - .5), l = (l = (a.getTime() - n.getTime()) / 864e5) - .5, M = Math.round(l);
        if (f = r(f), s = r(s), 0 !== M) D = M + "天" + f + "小时" + s + "分后开始"; else var D = f + "小时" + s + "分后开始";
        return D;
    },
    wxInterceptor: function() {
        wx.getStorageSync("userPersonalInfo") || wx.navigateTo({
            url: "/pages/auth/auth"
        });
    },
    countryName: function(e) {
        return {
            AD: "安道尔",
            AE: "阿拉伯联合酋长国",
            AF: "阿富汗",
            AG: "安提瓜和巴布达",
            AI: "安圭拉",
            AL: "阿尔巴尼亚",
            AM: "亚美尼亚",
            AN: "荷属安的列斯",
            AO: "安哥拉",
            AR: "阿根廷",
            AS: "美属萨摩亚",
            AT: "奥地利",
            AU: "澳大利亚",
            AW: "阿鲁巴",
            AZ: "阿塞拜疆",
            BA: "波斯尼亚和黑塞哥维那",
            BB: "巴巴多斯",
            BD: "孟加拉国",
            BE: "比利时",
            BF: "布基纳法索",
            BG: "保加利亚",
            BH: "巴林",
            BI: "布隆迪",
            BJ: "贝宁",
            BM: "百慕大",
            BN: "文莱",
            BO: "玻利维亚",
            BR: "巴西",
            BS: "巴哈马",
            BT: "不丹",
            BV: "布维岛",
            BW: "博茨瓦纳",
            BY: "白俄罗斯",
            BZ: "伯利兹",
            CA: "加拿大",
            CC: "可可 (基林) 群岛",
            CF: "中非共和国",
            CG: "刚果共和国",
            CH: "瑞士",
            CI: "科特迪瓦",
            CK: "库克群岛",
            CL: "智利",
            CM: "喀麦隆",
            CN: "中国",
            CO: "哥伦比亚",
            CR: "哥斯达黎加",
            CU: "古巴",
            CV: "佛得角",
            CX: "圣诞岛",
            CY: "塞浦路斯",
            CZ: "捷克",
            DE: "德国",
            DJ: "吉布提",
            DK: "丹麦",
            DM: "多米尼克",
            DO: "多米尼加共和国",
            DZ: "阿尔及利亚",
            EC: "厄瓜多尔",
            EE: "爱沙尼亚",
            EG: "埃及",
            EH: "西撒哈拉",
            ER: "厄立特里亚",
            ES: "西班牙",
            ET: "埃塞俄比亚",
            FI: "芬兰",
            FJ: "斐济",
            FK: "福克兰群岛 (马尔维纳斯群岛)",
            FM: "密克罗尼西亚联邦",
            FO: "法罗群岛",
            FR: "法国",
            GA: "加蓬",
            GB: "英国",
            GD: "格林纳达",
            GE: "格鲁吉亚",
            GH: "加纳",
            GI: "直布罗陀",
            GL: "格陵兰岛",
            GM: "冈比亚",
            GN: "几内亚",
            GQ: "赤道几内亚",
            GR: "希腊",
            GS: "南乔治亚岛和南桑威奇群岛",
            GT: "危地马拉",
            GU: "关岛",
            GW: "几内亚比绍",
            GY: "圭亚那",
            HK: "中国香港",
            HM: "赫德和麦克唐纳群岛",
            HN: "洪都拉斯",
            HR: "克罗地亚",
            HT: "海地",
            HU: "匈牙利",
            IO: "英属印度洋领地",
            IQ: "伊拉克",
            IR: "伊朗伊斯兰共和国",
            IS: "冰岛",
            IT: "意大利",
            JM: "牙买加",
            JO: "约旦",
            JP: "日本",
            KE: "肯尼亚",
            KG: "吉尔吉斯斯坦",
            KH: "柬埔寨",
            KI: "基里巴斯",
            KM: "科摩罗",
            KN: "圣基茨和尼维斯",
            KP: "朝鲜",
            KR: "韩国",
            KW: "科威特",
            KY: "开曼群岛",
            KZ: "哈萨克斯坦",
            LA: "老挝人民民主共和国",
            LB: "黎巴嫩",
            LC: "圣卢西亚",
            LI: "列支敦斯登",
            LK: "斯里兰卡",
            LR: "利比里亚",
            LS: "莱索托",
            LT: "立陶宛",
            LU: "卢森堡",
            LV: "拉托维亚",
            LY: "利比亚",
            MA: "摩洛哥",
            MC: "摩纳哥",
            MD: "摩尔多瓦共和国",
            ME: "黑山共和国",
            MG: "马达加斯加",
            MH: "马绍尔群岛",
            MK: "前南斯拉夫马其顿共和国",
            ML: "马里",
            MM: "缅甸",
            MN: "蒙古",
            MO: "中国澳门",
            MP: "北马里亚纳群岛",
            MR: "毛里塔尼亚",
            MS: "蒙特塞拉特",
            MT: "马耳他",
            MU: "毛里求斯",
            MV: "马尔代夫",
            MW: "马拉维",
            MX: "墨西哥",
            MY: "马来西亚",
            MZ: "莫桑比克",
            NA: "纳米比亚",
            NE: "尼日尔",
            NF: "诺福克岛",
            NG: "尼日利亚",
            NI: "尼加拉瓜",
            NL: "荷兰",
            NO: "挪威",
            NP: "尼泊尔",
            NR: "瑙鲁",
            NU: "纽埃",
            NZ: "新西兰",
            OM: "阿曼",
            PA: "巴拿马",
            PE: "秘鲁",
            PG: "巴布亚新几内亚",
            PH: "菲律宾",
            PK: "巴基斯坦",
            PL: "波兰",
            PN: "皮特凯恩",
            PR: "波多黎各",
            PS: "巴勒斯坦领土",
            PT: "葡萄牙",
            PW: "帕劳",
            PY: "巴拉圭",
            QA: "卡塔尔",
            RO: "罗马尼亚",
            RS: "塞尔维亚",
            RU: "俄罗斯联邦",
            RW: "卢旺达",
            SA: "沙特阿拉伯",
            SB: "所罗门群岛",
            SC: "塞舌尔",
            SD: "苏丹",
            SE: "瑞典",
            SG: "新加坡",
            SH: "圣海伦娜",
            SI: "斯洛文尼亚",
            SJ: "斯瓦尔巴岛和扬马延岛",
            SK: "斯洛伐克",
            SL: "塞拉利昂",
            SM: "圣马力诺",
            SN: "塞内加尔",
            SO: "索马里",
            SR: "苏里南",
            ST: "圣多美和普林西比",
            SV: "萨尔瓦多",
            SY: "阿拉伯叙利亚共和国",
            SZ: "斯威士兰",
            TC: "特克斯和凯科斯群岛",
            TD: "乍得",
            TG: "多哥",
            TH: "泰国",
            thai: "泰语",
            TJ: "塔吉克斯坦",
            TK: "托克劳",
            TL: "东帝汶",
            TM: "土库曼斯坦",
            TN: "突尼斯",
            TO: "汤加",
            TR: "土耳其",
            TT: "特立尼达和多巴哥",
            TV: "图瓦卢",
            TW: "中国台湾",
            TZ: "坦桑尼亚联合共和国",
            UA: "乌克兰",
            UG: "乌干达",
            UM: "美国本土外小岛屿",
            US: "美国",
            UY: "乌拉圭",
            UZ: "乌兹别克斯坦",
            VA: "梵蒂冈城国 (罗马教廷)",
            VC: "圣文森特和格林纳丁斯",
            VE: "委内瑞拉",
            VG: "英属维尔京群岛",
            VI: "美属维尔京群岛",
            VN: "越南",
            VU: "瓦努阿图",
            WS: "萨摩亚",
            YE: "也门",
            ZA: "南非",
            ZM: "赞比亚",
            ZR: "刚果民主共和国",
            ZW: "津巴布韦",
            ZZ: "其他国家或地区"
        }[e];
    },
    convertUTCTimeToLocalTime: function(t) {
        function r(e) {
            return e > 9 ? e : "0" + e;
        }
        if (!t) return "-";
        var n = e(t), a = n.getFullYear(), o = r(n.getMonth() + 1), i = r(n.getDate()), u = n.getHours();
        return a + "-" + o + "-" + i + "  " + (u = r(u)) + ":" + r(n.getMinutes());
    },
    amData: function(t) {
        var r = e(t), n = r.getFullYear(), a = r.getMonth() + 1, o = r.getDate(), i = r.getHours(), u = r.getMinutes();
        return a < 10 && (a = "0" + a), o < 10 && (o = "0" + o), i < 10 && (i = "0" + i), 
        u < 10 && (u = "0" + u), n + "." + a + "." + o + " " + i + ":" + u;
    },
    throttle: function(e, t, r) {
        var n = !1;
        return r || (r = {}), function() {
            var a = this, o = arguments;
            n || (!1 !== r.leading && e.apply(a, o), n = !0, setTimeout(function() {
                !1 !== r.trailing && e.apply(a, o), n = !1;
            }, t));
        };
    },
    debounce: function(e, t) {
        var r, t = t || 200;
        return function() {
            var n = this, a = arguments;
            console.log("timer", r), r && (console.log("realy"), clearTimeout(r)), r = setTimeout(function() {
                r = null, e.apply(n, a);
            }, t);
        };
    },
    dateTimeAgo: function(t) {
        var r = (t = e(t)).getTime(), n = new Date().getTime() - r;
        if (!(n < 0)) {
            var a = n / 2592e6, o = n / 6048e5, i = n / 864e5, u = n / 36e5, s = n / 6e4, g = n / 1e3;
            return a >= 1 ? a <= 12 ? parseInt(a) + "月前" : parseInt(a / 12) + "年前" : o >= 1 ? parseInt(o) + "周前" : i >= 1 ? parseInt(i) + "天前" : u >= 1 ? parseInt(u) + "小时前" : s >= 1 ? parseInt(s) + "分钟前" : parseInt(g) + "秒钟前";
        }
    }
};